-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve the example for ptr::copy #77385
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
@bors r+ rollup |
📌 Commit e58f3d3 has been approved by |
@@ -1901,11 +1901,21 @@ pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) { | |||
/// ``` | |||
/// use std::ptr; | |||
/// | |||
/// /// # Safety: | |||
/// /// * `ptr` must be correctly aligned for its type and non-zero. | |||
/// /// * `ptr` must be valid for reads of `elts` contiguous objects of type `T`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never heard of "contiguous objects"? Is this perhaps a new term? Also, s/of/for
.
/// /// * `ptr` must be valid for reads of `elts` contiguous objects of type `T`. | |
/// /// * `ptr` must be valid for reads of `elts` contiguous objects for type `T`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try ctrl+f 'contiguous' on https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#guarantees
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, contiguous
is there but I never heard of contiguous objects
. Try rg 'contiguous objects'
in rust or https://github.com/rust-lang/rust/search?q=%22contiguous+objects%22
/// /// # Safety: | ||
/// /// * `ptr` must be correctly aligned for its type and non-zero. | ||
/// /// * `ptr` must be valid for reads of `elts` contiguous objects of type `T`. | ||
/// /// * Those elements must not be used after calling this function unless `T: Copy`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? Is it only limited for Copy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if these are not Copy
you'll have a double-free. ptr::read
does not drop or move the source buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I guess that's true but should this be part of safety? I think it could be but I wonder if this should be here.
@@ -1901,11 +1901,21 @@ pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) { | |||
/// ``` | |||
/// use std::ptr; | |||
/// | |||
/// /// # Safety: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// /// # Safety: | |
/// /// # Safety | |
/// /// |
We usually have a space after Safety
for heading and don't have :
at the end.
Improve the example for ptr::copy Fixes rust-lang#77220
Rollup of 11 pull requests Successful merges: - rust-lang#76851 (Fix 'FIXME' about using NonZeroU32 instead of u32.) - rust-lang#76979 (Improve std::sys::windows::compat) - rust-lang#77111 (Stabilize slice_ptr_range.) - rust-lang#77147 (Split sys_common::Mutex in StaticMutex and MovableMutex.) - rust-lang#77312 (Remove outdated line from `publish_toolstate` hook) - rust-lang#77362 (Fix is_absolute on WASI) - rust-lang#77375 (rustc_metadata: Do not forget to encode inherent impls for foreign types) - rust-lang#77385 (Improve the example for ptr::copy) - rust-lang#77389 (Fix some clippy lints) - rust-lang#77399 (BTreeMap: use Unique::from to avoid a cast where type information exists) - rust-lang#77429 (Link `new` method in `DefautHasher`s doc) Failed merges: r? `@ghost`
Fixes #77220